import Shop_examineUIActionBase from './shop-examine-ui-action-base';

/**
 * 商家入驻审核表UI服务对象
 *
 * @export
 * @class Shop_examineUIAction
 * @extends {Shop_examineUIActionBase}
 */
export class Shop_examineUIAction extends Shop_examineUIActionBase {
    /**
     * 提交
     *
     * @param {any[]} args 数据
     * @param {*} [contextJO={}] 行为上下文
     * @param {*} [paramJO={}] 行为参数
     * @param {*} [$event] 事件
     * @param {*} [xData] 数据目标
     * @param {*} [container] 行为容器对象
     * @param {string} [srfParentDeName]
     * @returns {Promise<any>}
     * @memberof
     */
    public async SaveAndExit(args: any[], contextJO: any = {}, paramJO: any = {}, $event?: any, xData?: any, container?: any, srfParentDeName?: string): Promise<any> {
        let response: any;
        if (xData && xData.saveAndExit instanceof Function) {
            const backend = async () => {
                const _data = {};
                response = await xData.save(_data);
                if (response || response.status === 200) {
                    const {data: result} = response;
                    let _args: any[] = [];
                    if (Object.is(container.$util.typeOf(result), 'array')) {
                        _args = [...result];
                    } else if (Object.is(container.$util.typeOf(result), 'object')) {
                        _args = [{...result}];
                    } else {
                        _args = [...args];
                    }
                    container.context.shop_examine = _args[0].id;
                    const nextPSUIActionUIService: any = await this.globaluiservice.getService('shop_examine_ui_action');
                    if (nextPSUIActionUIService) {
                        nextPSUIActionUIService.Shop_examine_NoApp(_args, contextJO, paramJO, $event, xData, container);
                    }
                }
                return response;
            };

            return backend();
        } else if (container.saveAndExit && container.saveAndExit instanceof Function) {
            response = await xData.saveAndExit();
            if (response || response.status === 200) {
                container.$emit('closeview', [{ ...response.data }]);
            }
        }
        return response;
    }
}
// 默认导出
export default Shop_examineUIAction;
